package logic

import (
	"context"
	"wechat/models/mysql"

	"wechat/wechatrpc/internal/svc"
	"wechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MomentsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMomentsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MomentsListLogic {
	return &MomentsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 朋友圈展示
func (l *MomentsListLogic) MomentsList(in *wechatrpc.MomentsListRequest) (*wechatrpc.MomentsListResponse, error) {
	// todo: add your logic here and delete this line

	var moments []mysql.WechatMoments

	mysql.DB.Debug().Where("id = ?", in.Id).Find(&moments)

	var momentsList []*wechatrpc.MomentsList

	for _, i := range moments {
		list := wechatrpc.MomentsList{
			Context: i.Context,
			UserId:  i.UserId,
		}
		momentsList = append(momentsList, &list)
	}

	return &wechatrpc.MomentsListResponse{
		List: momentsList,
	}, nil
}
